import { getRequest, postRequest, putRequest, deleteRequest } from '@/libs/axios'

// 创建处方
export const createPrescription = (data) => {
  return postRequest('/prescription', data)
}

// 获取处方详情
export const getPrescriptionDetail = (id) => {
  return getRequest(`/prescription/${id}`)
}

// 分页查询处方列表
export const getPrescriptionPage = (params) => {
  return getRequest('/prescription/page', params)
}

// 更新处方状态
export const updatePrescriptionStatus = (id, status) => {
  return putRequest(`/prescription/${id}/status`, { status })
}

// 作废处方
export const invalidatePrescription = (id) => {
  return deleteRequest(`/prescription/${id}`)
}

// 获取药品列表
export const getMedicineList = (params) => {
  if (typeof params === 'string') {
    return getRequest(`/medicine/search?name=${encodeURIComponent(params)}`);
  }
  return getRequest('/medicine/search', params);
}

// 获取常用药品列表
export const getFrequentMedicines = () => {
  return getRequest('/medicine/frequent')
}

// 获取病历关联的处方列表
export const getPrescriptionsByMedicalRecordId = (medicalRecordId) => {
  return getRequest(`/prescription/medical-record/${medicalRecordId}`)
}

// 获取处方明细
export const getPrescriptionDetails = (medicalRecordId) => {
  return getRequest('/prescription-detail/list', {
    medicalRecordId
  });
}

/**
 * 更新处方
 * @param {Object} prescriptionDTO - 处方数据
 * @returns {Promise} 更新结果
 */
export const updatePrescription = (prescriptionDTO) => {
  return putRequest('/prescription', prescriptionDTO);
} 